user.factory('userService', function($http, $q, $log) {
	return {
		selectUserList: function() {
			var deferred = $q.defer() ;
			var promise = deferred.promise ;
			$http({
				method: 'GET',
				url: '/hake/userinfo/selectPage'
			}).success(function(result, status, headers, config) {
				if(result.httpCode == status) {
					deferred.resolve(result.data) ;
				} else{
					deferred.reject(result.msg)
				}
			}).error(function(result, status, headers, config) {
				deferred.reject("错误代码：" + status)
			});
			return promise ;
		},
		selectUserList2: function(ngDialog, pageNum, pageSize) {
			/*ngDialog.open({
			    template: '<img src="/hake-ui/framework/vendors/pageloader/images/loader1.GIF">',
			    plain: true,
			    showClose: false,
		        closeByDocument: true,
		        closeByEscape: false,
			    width: 500,
			    height: 200,
			});*/
			
			var deferred = $q.defer() ;
			var promise = deferred.promise ;
			$http({
				method: 'GET',
				url: '/hake/userinfo/selectPage?pageNum='+pageNum+'&pageSize='+pageSize
			}).success(function(result, status, headers, config) {
				if(result.httpCode == status) {
					ngDialog.closeAll();
					deferred.resolve(result.data) ;
				} else{
					deferred.reject(result.msg)
				}
			}).error(function(result, status, headers, config) {
				deferred.reject("错误代码：" + status)
			});
			return promise ;
		},
		
		add: function(data) {
			var deferred = $q.defer() ;
			var promise = deferred.promise ;
			console.info(data);
			$http({
				method: 'POST',
				url: '/hake/userinfo/insert',
				data: data
			}).success(function(result, status, headers, config) {
				deferred.resolve(result) ;
			}).error(function(result, status, headers, config) {
				deferred.reject(result) ;
			});
			
			return promise ;
		}
	}
})